<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>柯里化</title>
</head>

<body>
  <script>
    function add() {
      let args = [...arguments]

      let fn = function() {
        return add.apply(null, [...args, ...arguments])
      }
      fn.sum = function() {
        return args.reduce((a, b) => a + b)
      }
      return fn
    }
    console.log(add(1)(2)(3).sum());
  </script>
</body>

</html>